package com.demo.coretech.genericity;

import java.time.LocalDate;

/**
 * @Authors：gaoyang
 * @CreateTime：2021/11/30 13:47
 * @Description：todo
 */
public class PairTest2 {
    public static void main(String[] args) {
        LocalDate[] birthdays = {
                LocalDate.of(1906,12,4),
                LocalDate.of(1937,2,19),
                LocalDate.of(1919,4,9),
                LocalDate.of(1920,5,1)
        };
        Pair<LocalDate> mm = ArrayAlg1.minmax(birthdays);
        System.out.println("min="+mm.getFirst());
        System.out.println("max="+mm.getSecond());
    }
}

class ArrayAlg1{
    public static <T extends Comparable> Pair<T> minmax(T[] a){
        if (a==null||a.length==0){
            return null;
        }
        T min = a[0];
        T max = a[0];
        for (int i=1;i<a.length;i++){
            if (min.compareTo(a[i])>0){
                min = a[i];
            }
            if (max.compareTo(a[i])<0){
                max = a[i];
            }
        }
        return new Pair<>(min,max);
    }
}